<?php
session_start();

if (!isset($_SESSION['username'])) {
    header("Location: ../login.html");
    exit();
}

include 'config.php';

if ($_SERVER["REQUEST_METHOD"] == "GET") {
    $stmt = $conn->prepare("SELECT api, pid, miyao FROM epay WHERE id = 1");
    $stmt->execute();
    $result = $stmt->get_result();
    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        $response = [
            "code" => "200",
            "msg" => "查询成功",
            "data" => [
                "apiurl" => $row['api'],
                "pid" => $row['pid'],
                "key" => $row['miyao']
            ]
        ];
    } else {
        $response = [
            "code" => "404",
            "msg" => "未找到配置信息"
        ];
    }
    echo json_encode($response, JSON_UNESCAPED_UNICODE);
} else {
    header("HTTP/1.1 405 Method Not Allowed");
    exit("仅支持 GET 请求");
}
$conn->close();
?>